package cn.dujc.superkid.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import cn.dujc.core.adapter.BaseQuickAdapter;
import cn.dujc.core.ui.BaseActivity;
import cn.dujc.core.ui.BaseListActivity;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.adapter.MeRecordAdapter;
import cn.dujc.superkid.api.HttpHelper;
import cn.dujc.superkid.api.QMap;
import cn.dujc.superkid.api.Result;
import cn.dujc.superkid.api.ResultCallBack;
import cn.dujc.superkid.bean.LearningProcessResult;
import cn.dujc.superkid.bean.RecordBean;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.utils.Preferences;

public class MeRecordActivity extends BaseActivity {
    private MeRecordAdapter meRecordAdapter;
    RecyclerView recyclerView;
    List<RecordBean> datas;

    @Override
    public int getViewId() {
        return R.layout.activity_me_record_activity;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
        setTitle("学习记录");
        recyclerView = findViewById(R.id.me_record_recycler);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        meRecordAdapter = new MeRecordAdapter(this);
        recyclerView.setAdapter(meRecordAdapter);
        initData();
    }

    private void initData() {
        final RegisterResult loginResult = Preferences.getInstance().getLoginResult(MeRecordActivity.this);
        String uid = loginResult.getUid();
        List<RecordBean> liteList = DataSupport.findAll(RecordBean.class);
        datas = new ArrayList<>();
        for (int i = 0; i < liteList.size(); i++) {
            if (liteList.get(i).getUserId().equals(uid)) {
                datas.add(liteList.get(i));
            }
        }
        meRecordAdapter.setDatas(datas);
        if(liteList.size()==0){
            findViewById(R.id.record_emptv).setVisibility(View.VISIBLE);
        }
    }
}
